﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Gezel.Model;
using Weazel.Gezel.Model.Errors;
using Weazel.Gezel.Parser;

#endregion

namespace Weazel.Toad.Application.Actions
{
  public class ParseAndVerifyGezelModelAction : ActionBase
  {
    public ParseAndVerifyGezelModelAction()
    {
      Enabled = false;

      Application.Instance.SelectedItemChanged += 
        new EventHandler<SelectedItemChangedEventArgs>(Instance_SelectedItemChanged);
    }

    public override void Execute(object sender, EventArgs e)
    {
      if (Application.Instance.SelectedItem is Items.GezelTextFile)
      {
        Items.GezelTextFile file = 
          Application.Instance.SelectedItem as Items.GezelTextFile;

        List<ParseError> parseErrors = 
          new List<ParseError>();

        Model model = ParseModel.Parse(ref parseErrors, file.Contents, file.Filename);

				List<VerificationError> verificationErrors = null;
				List<VerificationWarning> warnings = null;

        model.Verify(ref verificationErrors, ref warnings);
      }
    }

    void Instance_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
    {
      Enabled = e.SelectedItem is Items.GezelTextFile ? true : false;
    }
  }
}
